﻿using Harmontronics.DataAccess.IOperate.Business;
using Harmontronics.Model.Common;
using Harmontronics.Model.Dto.Model;
using Harmontronics.Model.Entitys;
using Harmontronics.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Harmontronics.DataAccess.Operate.Business
{
    public class PartOperate : IPartOperate
    {
        private HcDbContext _db { get; set; }
        public PartOperate(HcDbContext db)
        {
            _db = db;
        }
        //查询所有
        public List<Part> GetAllPartList()
        {

            return _db.Parts.ToList();
        }

        public Part GetPartById(string id)
        {
            return _db.Parts.SingleOrDefault(i => i.PartId == id);
        }

        public List<Part> GetPartByIdList(List<string> ids)
        {
            return _db.Parts.Where(i => ids.Contains(i.PartId)).ToList();
        }

        public void AddPart(Part entity)
        {
            _db.Parts.Add(entity);
        }

        public void UpdatePart(Part entity)
        {
            _db.Parts.Update(entity);
        }

        public void DeletePart(Part entity)
        {
            _db.Parts.Remove(entity);
        }

        public void BatchDelPart(List<Part> entity)
        {
            _db.Parts.RemoveRange(entity);

        }
    }
}
